package org.jeecg.modules.workflow.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.common.mybatis.query.QueryWrapperX;
import org.jeecg.modules.workflow.entity.BpmTaskAssignRule;
import org.springframework.lang.Nullable;

import java.util.List;

/**
 * Bpm 任务规则Mapper接口
 *
 * @author whnk
 * @date 2022-04-20
 */
public interface BpmTaskAssignRuleMapper extends BaseMapper<BpmTaskAssignRule> {

    default List<BpmTaskAssignRule> selectListByProcessDefinitionId(String processDefinitionId,
                                                                    @Nullable String taskDefinitionKey) {
        return selectList(new QueryWrapperX<BpmTaskAssignRule>()
                .eq("process_definition_id", processDefinitionId)
                .eqIfPresent("task_definition_key", taskDefinitionKey));
    }

    default List<BpmTaskAssignRule> selectListByModelId(String modelId) {
        return selectList(new QueryWrapperX<BpmTaskAssignRule>()
                .eq("model_id", modelId)
                .isNull("process_definition_id"));
    }

    default BpmTaskAssignRule selectListByModelIdAndTaskDefinitionKey(String modelId,
                                                                      String taskDefinitionKey) {
        return selectOne(new QueryWrapperX<BpmTaskAssignRule>()
                .eq("model_id", modelId)
                .isNull("process_definition_id")
                .eq("task_definition_key", taskDefinitionKey));
    }
}
